home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.3 / Printer / src / HP / render.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  4.4 KB  |  177 lines

  1. /*
  2.     HP_LaserJet driver.
  3.     David Berezowski - May/87.
  4.  
  5.   Copyright (c) 1988 Commodore-Amiga, Inc.
  6.  
  7.   Executables based on this information may be used in software
  8.   for Commodore Amiga computers.  All other rights reserved.
  9.  
  10.   This information is provided "as is"; no warranties are made.
  11.   All use is at your own risk, and no liability or responsibility is assumed.
  12. */
  13.  
  14.  
  15. #include <exec/types.h>
  16. #include <exec/nodes.h>
  17. #include <exec/lists.h>
  18. #include <exec/memory.h>
  19. #include "../printer/prtbase.h"
  20. #include "../printer/printer.h"
  21.  
  22. #define NUMSTARTCMD    7    /* # of cmd bytes before binary data */
  23. #define NUMENDCMD    0    /* # of cmd bytes after binary data */
  24. #define NUMTOTALCMD (NUMSTARTCMD + NUMENDCMD)    /* total of above */
  25.  
  26. extern SetDensity();
  27. /*
  28.     00-04    \033&l0L    perf skip mode off
  29.     05-11    \033*t075R    set raster graphics resolution (dpi)
  30.     12-16    \033*r0A    start raster graphics
  31. */
  32. char StartCmd[17] = "\033&l0L\033*t075R\033*r0A";
  33.  
  34. Render(ct, x, y, status)
  35. long ct, x, y, status;
  36. {
  37.     extern void *AllocMem(), FreeMem();
  38.  
  39.     extern struct PrinterData *PD;
  40.     extern struct PrinterExtendedData *PED;
  41.  
  42.     static UWORD RowSize, BufSize, TotalBufSize, dataoffset;
  43.     static UWORD huns, tens, ones; /* used to program buffer size */
  44.     UBYTE *ptr, *ptrstart;
  45.     int i, err;
  46.  
  47.     switch(status) {
  48.         case 0 : /* Master Initialization */
  49.             /*
  50.                 ct    - pointer to IODRPReq structure.
  51.                 x    - width of printed picture in pixels.
  52.                 y    - height of printed picture in pixels.
  53.             */
  54.             RowSize = (x + 7) / 8;
  55.             BufSize = RowSize + NUMTOTALCMD;
  56.             TotalBufSize = BufSize * 2;
  57.             PD->pd_PrintBuf = AllocMem(TotalBufSize, MEMF_PUBLIC);
  58.             if (PD->pd_PrintBuf == NULL) {
  59.                 err = PDERR_BUFFERMEMORY; /* no mem */
  60.             }
  61.             else {
  62.                 ptr = PD->pd_PrintBuf;
  63.                 *ptr++ = 27;
  64.                 *ptr++ = '*';
  65.                 *ptr++ = 'b';    /* transfer raster graphics */
  66.                 *ptr++ = huns | '0';
  67.                 *ptr++ = tens | '0';
  68.                 *ptr++ = ones | '0';    /* printout width */
  69.                 *ptr = 'W';        /* terminator */
  70.                 ptr = &PD->pd_PrintBuf[BufSize];
  71.                 *ptr++ = 27;
  72.                 *ptr++ = '*';
  73.                 *ptr++ = 'b';    /* transfer raster graphics */
  74.                 *ptr++ = huns | '0';
  75.                 *ptr++ = tens | '0';
  76.                 *ptr++ = ones | '0';    /* printout width */
  77.                 *ptr = 'W';        /* terminator */
  78.                 dataoffset = NUMSTARTCMD;
  79.             /* perf skip mode off, set dpi, start raster gfx */
  80.                 err = (*(PD->pd_PWrite))(StartCmd, 17);
  81.             }
  82.             break;
  83.  
  84.         case 1 : /* Scale, Dither and Render */
  85.             /*
  86.                 ct    - pointer to PrtInfo structure.
  87.                 x    - 0.
  88.                 y    - row # (0 to Height - 1).
  89.             */
  90.             Transfer(ct, y, &PD->pd_PrintBuf[dataoffset]);
  91.             err = PDERR_NOERR; /* all ok */
  92.             break;
  93.  
  94.         case 2 : /* Dump Buffer to Printer */
  95.             /*
  96.                 ct    - 0.
  97.                 x    - 0.
  98.                 y    - # of rows sent (1 to NumRows).
  99.  
  100.                 White-space strip.
  101.             */
  102.             i = RowSize;
  103.             ptrstart = &PD->pd_PrintBuf[dataoffset - NUMSTARTCMD];
  104.             ptr = ptrstart + NUMSTARTCMD + i - 1;
  105.             while (i > 0 && *ptr == 0) {
  106.                 i--;
  107.                 ptr--;
  108.             }
  109.             ptr = ptrstart + 3; /* get ptr to density info */
  110.             *ptr++ = (huns = i / 100) | '0';
  111.             *ptr++ = (i - huns * 100) / 10 | '0';
  112.             *ptr = i % 10 | '0'; /* set printout width */
  113.             err = (*(PD->pd_PWrite))(ptrstart, i + NUMTOTALCMD);
  114.             if (err == PDERR_NOERR) {
  115.                 dataoffset = (dataoffset == NUMSTARTCMD ?
  116.                     BufSize : 0) + NUMSTARTCMD;
  117.             }
  118.             break;
  119.  
  120.         case 3 : /* Clear and Init Buffer */
  121.             /*
  122.                 ct    - 0.
  123.                 x    - 0.
  124.                 y    - 0.
  125.             */
  126.             ptr = &PD->pd_PrintBuf[dataoffset];
  127.             i = RowSize;
  128.             do {
  129.                 *ptr++ = 0;
  130.             } while (--i);
  131.             break;
  132.  
  133.         case 4 : /* Close Down */
  134.             /*
  135.                 ct    - error code.
  136.                 x    - io_Special flag from IODRPReq struct
  137.                 y    - 0.
  138.             */
  139.             err = PDERR_NOERR; /* assume all ok */
  140.             /* if user did not cancel the print */
  141.             if (ct != PDERR_CANCEL) {
  142.                 /* end raster graphics, perf skip mode on */
  143.                 if ((err = (*(PD->pd_PWrite))
  144.                     ("\033*rB\033&l1L", 9)) == PDERR_NOERR) {
  145.                     /* if want to unload paper */
  146.                     if (!(x & SPECIAL_NOFORMFEED)) {
  147.                         /* eject paper */
  148.                         err = (*(PD->pd_PWrite))
  149.                             ("\014", 1);
  150.                     }
  151.                 }
  152.             }
  153.             /*
  154.                 flag that there is no alpha data waiting that
  155.                 needs a formfeed (since we just did one)
  156.             */
  157.             PED->ped_PrintMode = 0;
  158.              /* wait for both buffers to empty */
  159.             (*(PD->pd_PBothReady))();
  160.             if (PD->pd_PrintBuf != NULL) {
  161.                 FreeMem(PD->pd_PrintBuf, TotalBufSize);
  162.             }
  163.             break;
  164.  
  165.         case 5 : /* Pre-Master Initialization */
  166.             /*
  167.                 ct    - 0 or pointer to IODRPReq structure.
  168.                 x    - io_Special flag from IODRPReq struct
  169.                 y    - 0.
  170.             */
  171.             /* select density */
  172.             SetDensity(x & SPECIAL_DENSITYMASK);
  173.             break;
  174.     }
  175.     return(err);
  176. }
  177.